var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("PromoNodeArrItem"),
i = cc._decorator,
a = i.ccclass,
r = i.property,
s = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.mDatas = null;
        t.itemList = [];
        t.prefab = null;
        t.layout = null;
        t.scroll = !1;
        t.initPos = !1;
        t.showLeft = !1;
        return t
    }
    t.prototype.onLoad = function() {
        SDK.Base.Event.on("getData", this.initData, this);
        this.initData()
    };
    t.prototype.onDestroy = function() {
        SDK.Base.Event.off("getData", this.initData, this)
    };
    t.prototype.initData = function() {
        if (SDK.Mgr.Inst.hasPromoData && (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.oppo || SDK.Mgr.Inst.isAdOpen)) {
            this.node.active = !0;
            this.mDatas = Config.Base.promoData;
            this.setData()
        } else this.node.active = !1
    };
    t.prototype.setData = function() {
        if (this.mDatas.content.length > 0) {
            for (var e = 0; e < Math.min(this.mDatas.content.length, 9); e++) {
                var t = cc.instantiate(this.prefab);
                t.parent = this.layout;
                t.active = !0;
                var n = t.getComponent(o.default);
                null != n && this.itemList.push(n);
                n.setData(this.mDatas.content[e])
            }
            if (this.itemList.length > 5) {
                this.initPos = !0;
                this.scroll = !0
            }
        }
    };
    Object.defineProperty(t.prototype, "maxLeft", {
        get: function() {
            var e = (this.layout.width - this.layout.parent.width) / 2;
            this.scroll && (e += 20);
            return e
        },
        enumerable: !1,
        configurable: !0
    });
    Object.defineProperty(t.prototype, "maxRight", {
        get: function() {
            var e = (this.layout.parent.width - this.layout.width) / 2;
            this.scroll && (e -= 20);
            return e
        },
        enumerable: !1,
        configurable: !0
    });
    t.prototype.update = function(e) {
        if (this.scroll) {
            if (this.initPos) {
                if (! (this.layout.width > 0)) return;
                this.layout.x = this.maxLeft;
                this.initPos = !1
            }
            this.layout.x <= this.maxRight ? this.showLeft = !0 : this.layout.x >= this.maxLeft && (this.showLeft = !1);
            this.showLeft ? this.layout.x += 50 * e: this.layout.x -= 50 * e
        } else this.layout.x = this.maxLeft
    };
    __decorate([r(cc.Node)], t.prototype, "prefab", void 0);
    __decorate([r(cc.Node)], t.prototype, "layout", void 0);
    return __decorate([a], t)
} (cc.Component);
n.default = s